<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		ScriptPlanet.eu															/
/	Site:			http://www.scriptplanet.eu												/
/	Email:			support@scriptplanet.eu													/
/	Support:		http://www.scriptplanet.eu/support										/
/	Copyright:		2011 (c) ScriptPlanet.eu												/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0001																	/
/																							/
/========================================== JooSam ========================================*/

// Joomla security
defined('_JEXEC') or die;
 
## JooSam Master Helper
class JoosamHelper{

	## Submenu
	public static function addSubmenu($vName){
		// Submenu Home
		JSubMenuHelper::addEntry(JText::_('COM_JOOSAM_SUBMENU_JOOSAM'),'index.php?option=com_joosam&view=joosam',$vName == 'joosam');
        // Submenu Settings
		JSubMenuHelper::addEntry(JText::_('COM_JOOSAM_SUBMENU_SETTINGS'),'index.php?option=com_joosam&view=settings',$vName == 'settings');
		// Submenu Text Strings
		JSubMenuHelper::addEntry(JText::_('COM_JOOSAM_SUBMENU_TEXTSTRINGS'),'index.php?option=com_joosam&view=textstrings',$vName == 'textstrings');
		// Submenu Events
		JSubMenuHelper::addEntry(JText::_('COM_JOOSAM_SUBMENU_EVENTS'),'index.php?option=com_joosam&view=events',$vName == 'events');
		// Submenu Requests
		JSubMenuHelper::addEntry(JText::_('COM_JOOSAM_SUBMENU_REQUESTS'),'index.php?option=com_joosam&view=requests',$vName == 'requests');
		// Submenu Modules
		JSubMenuHelper::addEntry(JText::_('COM_JOOSAM_SUBMENU_MODPLG'),'index.php?option=com_joosam&view=modplg',$vName == 'modplg');
    }

	## Actions
	public static function getActions(){
		
		$user	= JFactory::getUser();
		$result	= new JObject;
		$assetName = 'com_joosam';
		$actions = array(
			'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.state', 'core.delete'
		);
		foreach ($actions as $action) {
			$result->set($action,	$user->authorise($action, $assetName));
		}
		return $result;
	}

	## JooSam Password Function
	public static function jscrypt($type,$password){

		require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joosam' . DS . 'helpers' . DS . 'jscrypt.php';
		$engine = new JoosamHelperJscrypt;

		## Check if mcrypt is installed
		if(function_exists('mcrypt_module_open')){
			
			## Encode The Password
			if ($type == 'encode' AND $password != ''){
				$result = $engine->jsencrypt($password);
				return $result;
			}

			## Decode The Password
			else if($type == 'decode' AND $password != ''){
				$result = $engine->jsdecrypt($password);
				return $result;
			}

			## False
			else{ return false; }
		}

		## Password encryptor when no mcrypt is installed
		else{

			## Encode The Password
			if ($type == 'encode' AND $password != ''){
				$result = $engine->jsbaseEncrypt($password);
				return $result;
			}

			## Decode The Password
			else if($type == 'decode' AND $password != ''){
				$result = $engine->jsbaseDecrypt($password);
				return $result;
			}

			## False
			else{ return false; }
		}
	}

	## SAM DataBase connector
	public static function samDBO($option,$query){

			require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joosam' . DS . 'helpers' . DS . 'samdb.php';
			$engine = new SamdbHelper;
			$result = $engine->samDBO($option,$query);
			return $result;
	}
}
?>
			